home *** CD-ROM | disk | FTP | other *** search
/ Internet Info 1994 March / Internet Info CD-ROM (Walnut Creek) (March 1994).iso / answers / comp / g++-FAQ / plain < prev    next >
Text File  |  1994-04-15  |  40KB  |  941 lines

  1. Newsgroups: gnu.g++.help,comp.lang.c++,news.answers,comp.answers
  2. Path: bloom-beacon.mit.edu!hookup!swrinde!sgiblab!chronos.synopsys.com!news.synopsys.com!jbuck
  3. From: jbuck@synopsys.com (Joe Buck)
  4. Subject: FAQ for g++ and libg++, plain text version [Revised 01 Mar 1994]
  5. Message-ID: <g++FAQ_04_15_1994_texi@synopsys.com>
  6. Followup-To: poster
  7. Originator: jbuck@deerslayer
  8. Sender: usenet@Synopsys.Com
  9. Supersedes: <g++FAQ_04_01_1994_texi@synopsys.com>
  10. Organization: Synopsys Inc.
  11. Date: Fri, 15 Apr 1994 16:07:38 GMT
  12. Approved: news-answers-request@MIT.edu
  13. Expires: Sun, 15 May 1994 00:00:00 GMT
  14. Lines: 924
  15. Xref: bloom-beacon.mit.edu gnu.g++.help:3388 comp.lang.c++:43413 news.answers:18082 comp.answers:4919
  16.  
  17. Archive-name: g++-FAQ/plain
  18. Last-modified: 01 Mar 1994
  19. Frequency: bimonthly
  20.  
  21. [ this is the plain text version, the parent is the texinfo version ]
  22.  
  23.  
  24. Preface
  25. *******
  26.  
  27.    This is a list of frequently asked questions (FAQ) for g++ users;
  28. thanks to all those who sent suggestions for improvements.  Thanks to
  29. Marcus Speh for doing the index.
  30.  
  31.    Many FAQ's, including this one, are available on the archive site
  32. rtfm.mit.edu, in the directory `pub/usenet/news.answers'.  This FAQ may
  33. be found in the subdirectory g++-FAQ.
  34.  
  35.    Some information in this FAQ was developed for earlier versions of
  36. the compiler and may now be obsolete.  Please send corrections.
  37.  
  38.    I'm looking for new questions (*with* answers), better answers, or
  39. both.  One thing that's missing is a section on templates and template
  40. problems with g++; I'm looking for contributions on this score.  You
  41. can mail comments, suggestions, flames, etc. to jbuck@synopsys.com.
  42. Please don't assume, though, that because my name is on this thing that
  43. I am the world expert on g++/C++ and you should mail all your tricky
  44. questions to me.  I'd like to be helpful but I'm getting more of this
  45. than I can deal with lately.  Also please don't assume that I am an
  46. official spokesman for g++, FSF, or Cygnus; I'm not.
  47.  
  48.    This FAQ is intended to supplement, not replace, Marshall Cline's
  49. excellent FAQ for the C++ language and for the newsgroup comp.lang.c++.
  50. Especially if g++ is the first C++ compiler you've ever used, the
  51. question "How do I do <X> with g++?" is probably really "How do I do
  52. <X> in C++?".  You can obtain the C++ FAQ by anonymous FTP from
  53. sun.soe.clarkson.edu [128.153.12.3], in the file `~ftp/pub/C++/FAQ'.
  54. (There is also a mail server for that FAQ, but it seems to be broken).
  55.  
  56.  
  57. Obtaining Source Code
  58. *********************
  59.  
  60.  
  61. How do I get a copy of g++ for Unix?
  62. ====================================
  63.  
  64.    First, you may already have it if you have gcc for your platform;
  65. g++ and gcc are combined now (as of gcc version 2.0).
  66.  
  67.    You can get g++ from a friend who has a copy, by anonymous FTP or
  68. UUCP, or by ordering a tape or CD-ROM from the Free Software Foundation.
  69.  
  70.    The Free Software Foundation is a nonprofit organization that
  71. distributes software and manuals to raise funds for more GNU
  72. development.  Getting your copy from the FSF contributes directly to
  73. paying staff to develop GNU software.  CD-ROMs cost $400 if an
  74. organization is buying, or $100 if an individual is buying.  Tapes cost
  75. around $200 depending on media type.  I recommend asking for version 2,
  76. not version 1, of g++.
  77.  
  78.    For more information about ordering from the FSF, contact
  79. gnu@prep.ai.mit.edu, phone (617) 876-3296 or anonymous ftp file
  80. `/pub/gnu/GNUinfo/ORDERS' from prep.ai.mit.edu or one of the sites
  81. listed below.
  82.  
  83.    Here is a list of anonymous FTP archive sites for GNU software.
  84.  
  85.      ASIA: ftp.cs.titech.ac.jp, utsun.s.u-tokyo.ac.jp:/ftpsync/prep,
  86.           cair.kaist.ac.kr:/pub/gnu
  87.      AUSTRALIA: archie.oz.au:/gnu (archie.oz or archie.oz.au for ACSnet)
  88.      AFRICA: ftp.sun.ac.za:/pub/gnu
  89.      MIDDLE-EAST: ftp.technion.ac.il:/pub/unsupported/gnu
  90.      EUROPE: irisa.irisa.fr:/pub/gnu, grasp1.univ-lyon1.fr:pub/gnu,
  91.           ftp.mcc.ac.uk, unix.hensa.ac.uk:/pub/uunet/systems/gnu,
  92.           src.doc.ic.ac.uk:/gnu, ftp.win.tue.nl, ugle.unit.no, ftp.denet.dk,
  93.           ftp.informatik.rwth-aachen.de:/pub/gnu, ftp.informatik.tu-muenchen.de,
  94.           ftp.eunet.ch, nic.switch.ch:/mirror/gnu, nic.funet.fi:/pub/gnu,
  95.           isy.liu.se, ftp.stacken.kth.se, ftp.luth.se:/pub/unix/gnu, archive.eu.net
  96.      CANADA: ftp.cs.ubc.ca:/mirror2/gnu
  97.      USA: wuarchive.wustl.edu:/mirrors/gnu, labrea.stanford.edu,
  98.           ftp.kpc.com:/pub/mirror/gnu, ftp.cs.widener.edu, uxc.cso.uiuc.edu,
  99.           col.hp.com:/mirrors/gnu, ftp.cs.columbia.edu:/archives/gnu/prep,
  100.           gatekeeper.dec.com:/pub/GNU, ftp.uu.net:/systems/gnu
  101.  
  102.    The "official site" is prep.ai.mit.edu, but your transfer will
  103. probably go faster if you use one of the above machines.
  104.  
  105.    Most GNU utilities are compressed with "gzip", the GNU compression
  106. utility.  All GNU archive sites should have a copy of this program,
  107. which you will need to uncompress the distributions.
  108.  
  109.    UUNET customers can get GNU sources from UUNET via UUCP.  UUCP-only
  110. sites can get GNU sources by "anonymous UUCP" from site "osu-cis" at
  111. Ohio State University.  You pay for the long-distance call to OSU; the
  112. price isn't too bad on weekends at 9600 bps.  Send mail to
  113. uucp@cis.ohio-state.edu or osu-cis!uucp for more information.
  114.  
  115.    OSU lines are often busy.  If you're in the USA, and are willing to
  116. spend more money, you can get sources via UUCP from UUNET using their
  117. 900 number: 1-900-GOT-SRCS (900 numbers don't work internationally).
  118. You will be billed $0.50/minute by your phone company.
  119.  
  120.    Don't forget to retrieve libg++ as well!
  121.  
  122.  
  123. Getting gcc/g++ for the HP Precision Architecture
  124. =================================================
  125.  
  126.    If you use the HP Precision Architecture (HP-9000/7xx and
  127. HP-9000/8xx) and you want to use debugging, you'll need to grab a
  128. special version of GAS from the University of Utah, site
  129. jaguar.cs.utah.edu.  Look in the `/dist' directory for gas-2.2.u4.  A
  130. non-standard debug format is used, since until recently HP considered
  131. their debug format a trade secret.  Thanks to the work of lots of good
  132. folks both inside and outside HP, the company has seen the error of its
  133. ways and has now released the required information.  The team at the
  134. University of Utah now has code that understands the native HP format.
  135. For now, the GNU debugger, GDB, understands the debug format produced
  136. by this version of GAS, but not the format produced by HP's compilers.
  137. However, another there is another version of GDB avaiable from this site
  138. that understands the debug format produced by the HP C compiler (but no
  139. version that understands both, unfortunately).
  140.  
  141.    Some enhancements for the HP that haven't been integrated back into
  142. the official GCC are available from the same site in version
  143. gcc-2.5.8.u5.  The site also has GDB (4.12.u1), GAS (2.2.u4), and
  144. libg++ (2.5.2.u3).
  145.  
  146.    I recommend that HP users use the Utah versions of the tools (see
  147. above).  HP GNU users can also find useful stuff on the site
  148. geod.emr.ca in the `/pub/GNU-HP' directory.
  149.  
  150.  
  151. Getting gcc/g++ binaries for Solaris 2.x
  152. ========================================
  153.  
  154.    "Sun took the C compiler out of Solaris 2.x.  Am I stuck?"
  155.  
  156.    No; prep.ai.mit.edu and its mirror sites provide GCC binaries for
  157. Solaris.  As a rule, these binaries are not updated as often as the
  158. sources are, so if you want the very latest version of gcc/g++, you may
  159. need to grab and install binaries for an older version and use it to
  160. bootstrap the latest version from source.
  161.  
  162.    The latest gcc binaries on prep.ai.mit.edu and its mirror sites are
  163. for version 2.5.6 for Solaris on the Sparc, and version 2.4.5 for
  164. Solaris on Intel 386/486 machines.  There are also binaries for "gzip",
  165. the GNU compression utility, which you'll need for uncompressing the
  166. binary distribution.
  167.  
  168.  
  169. How do I get a copy of g++ for (some other platform)?
  170. =====================================================
  171.  
  172.    The standard gcc/g++ distribution includes VMS support.  Since the
  173. FSF people don't use VMS, it's likely to be somewhat less solid than
  174. the Unix version.  Precompiled copies of g++ and libg++ in
  175. VMS-installable form are available by FTP from mango.rsmas.miami.edu.
  176.  
  177.    DJ Delorie has ported gcc/g++ to MS-DOS; this port is popularly
  178. known as "DJGPP" (the P's stand for "plus").  It can be found on many
  179. FTP archive sites; its "home" is on oak.oakland.edu, directory
  180. `~ftp/pub/msdos/djgpp'.
  181.  
  182.    The latest version of DJGPP is 1.11.maint2.  This version runs under
  183. Windows 3.x.  It is a port of gcc 2.5.7.
  184.  
  185.    FSF sells floppies with DJGPP on them; see above for ordering
  186. software from the FSF.
  187.  
  188.    For information on Amiga ports of gcc/g++, retrieve the file
  189. `/pub/gnu/MicrosPorts/Amiga' from prep.ai.mit.edu, or write to Markus
  190. M. Wild <wild@nessie.cs.id.ethz.ch>, who I hope won't be too upset that
  191. I mentioned his name here.
  192.  
  193.    A port of gcc to the Atari ST can be found on the site
  194. "atari.archive.umich.edu", under `/atari/Gnustuff/Tos', along with many
  195. other GNU programs.  This version is usually the same as the latest FSF
  196. release.  See the "Software FAQ" for the Usenet group
  197. "comp.sys.atari.st" for more information.
  198.  
  199.    There are two different ports of gcc to OS/2, the so-called EMX
  200. port, and a port called "gcc/2".  The EMX port's C library attempts to
  201. provide a Unix-like environment; gcc/2 uses a rather buggy port of the
  202. BSD libc.  For more information ask around on
  203. "comp.os.os2.programmer.misc".  gcc/2, together with other GNUware for
  204. OS/2, can be obtained by FTP from
  205.  
  206.      ftp-os2.cdrom.com(192.153.46.2) in /pub/os2/2_x/unix/gnu
  207.      ftp-os2.nmsu.edu (128.123.35.151) in /pub/os2/2_x/unix/gnu
  208.      luga.latrobe.edu.au (131.172.2.2) in /pub/os2/2_x/unix/gnu
  209.  
  210.    The current maintainer of the gcc/2 port is Colin Jensen (Michael
  211. Johnson did the original port).  His address is cjensen@netcom.com.
  212.  
  213.    Eberhard Mattes did the EMX port.  His address is
  214. mattes@azu.informatik.uni-stuttgart.de.
  215.  
  216.    Because the legal policies of Apple threaten the long-term goals of
  217. FSF, as well as the concept of free software, no support will be lent to
  218. efforts to port GNU software to Macintosh or other Apple hardware.
  219.  
  220.  
  221. But I can only find g++-1.42!
  222. =============================
  223.  
  224.    "I keep hearing people talking about g++ 2.5.8 (or some other number
  225. starting with 2), but the latest version I can find is g++ 1.42.  Where
  226. is it?"
  227.  
  228.    As of gcc 2.0, C, C++, and Objective-C as well are all combined into
  229. a single distribution called gcc.  If you get gcc you already have g++.
  230. The standard installation procedure for any gcc version 2 compiler will
  231. install the C++ compiler as well.
  232.  
  233.    One could argue that we shouldn't even refer to "g++-2.x.y" but it's
  234. a convention.  It means "the C++ compiler included with gcc-2.x.y."
  235.  
  236.  
  237. What is the latest version of gcc, g++, and libg++?
  238. ===================================================
  239.  
  240.    The latest "2.x" version of gcc/g++ is 2.5.8, released January 23,
  241. 1994.  The latest version of libg++ is 2.5.3, released December 21,
  242. 1993.  Don't use 2.5.x, with x less than 5, for C++ code; there were
  243. some serious bugs that didn't have easy workarounds.
  244.  
  245.    For some non-Unix platforms, the latest port of gcc may be an earlier
  246. version (2.4.5, say).  You'll need to use a version of libg++ that has
  247. the same first two digits as the compiler version, e.g. use libg++ 2.4
  248. with gcc version 2.4.5.
  249.  
  250.    The latest "1.x" version of gcc is 1.42, and the latest "1.x"
  251. version of g++ is 1.42.0.  While gcc 1.42 is quite usable for C
  252. programs, I recommend against using g++ 1.x except in special
  253. circumstances.
  254.  
  255.  
  256. Installation Issues and Problems
  257. ********************************
  258.  
  259.  
  260. I can't build g++ 1.x.y with gcc-2.x.y!
  261. =======================================
  262.  
  263.    "I obtained gcc-2.x.y and g++ 1.x.y and I'm trying to build it, but
  264. I'm having major problems.  What's going on?"
  265.  
  266.    If you wish to build g++-1.42, you must obtain gcc-1.42 first.  The
  267. installation instructions for g++ version 1 leave a lot to be desired,
  268. unfortunately, and I would recommend that, unless you have a special
  269. reason for needing the 1.x compiler, that C++ users use the latest
  270. g++-2.x version, as it is the version that is being actively maintained.
  271.  
  272.    There is no template support in g++-1.x, and it is generally much
  273. further away from the ANSI draft standard than g++-2.x is.
  274.  
  275.  
  276. OK, I've obtained gcc; what else do I need?
  277. ===========================================
  278.  
  279.    First off, you'll want libg++ as you can do almost nothing without it
  280. (unless you replace it with some other class library).
  281.  
  282.    Second, depending on your platform, you may need "gas", the GNU
  283. assembler, or the GNU linker (see next question).
  284.  
  285.    Finally, while it is not required, you'll almost certainly want the
  286. GNU debugger, gdb.  The latest version is 4.12, released Feb. 3, 1994.
  287. Other debuggers (like dbx, for example) will normally not be able to
  288. understand at least some of the debug information produced by g++.
  289.  
  290.  
  291. Should I use the GNU linker, or should I use "collect"?
  292. =======================================================
  293.  
  294.    First off, for novices: special measures must be taken with C++ to
  295. arrange for the calling of constructors for global or static objects
  296. before the execution of your program, and for the calling of
  297. destructors at the end.  (Exception: System VR3 and System VR4 linkers
  298. support user-defined segments; g++ on these systems requires neither
  299. the GNU linker nor collect.  So if you have such a system, the answer
  300. is that you don't need either one).
  301.  
  302.    If you have experience with AT&T's "cfront", this function is
  303. performed there by programs named "patch" or "munch".  With GNU C++, it
  304. is performed either by the GNU linker or by a program known as
  305. "collect".  The collect program is part of the gcc-2.x distribution;
  306. you can obtain the GNU linker separately as part of the "binutils"
  307. package.  The latest version of binutils is 2.3, released Nov. 11, 1993.
  308.  
  309.    (To be technical, it's "collect2"; there were originally several
  310. alternative versions of collect, and this is the one that survived).
  311.  
  312.    There are advantages and disadvantages to either choice.
  313.  
  314.    Advantages of the GNU linker:
  315.  
  316.    It's faster than using collect - collect basically runs the standard
  317. Unix linker on your program twice, inserting some extra code after the
  318. first pass to call the constructors.  This is a sizable time penalty
  319. for large programs.  The GNU linker does not require this extra pass.
  320.  
  321.    GNU ld reports undefined symbols using their true names, not the
  322. mangled names.
  323.  
  324.    If there are undefined symbols, GNU ld reports which object file(s)
  325. refer to the undefined symbol(s).
  326.  
  327.    As of binutils version 2.2, on systems that use the so-called "a.out"
  328. debug format (e.g. Suns running SunOS 4.x), the GNU linker compresses
  329. the debug symbol table considerably, which in at least some cases may
  330. make up, in disk space, for its inability to use shared libraries.
  331.  
  332.    Advantages of collect:
  333.  
  334.    If your native linker supports shared libraries, you can use shared
  335. libraries with collect.  The GNU linker does not (yet) support shared
  336. libraries.
  337.  
  338.    Note: using existing shared libraries (X and libc, for example) works
  339. very nicely; generating shared libraries from g++-compiled code is
  340. another matter, generally requiring OS-dependent tricks if it is
  341. possible at all.
  342.  
  343.    Ron Guilmette has written a set of patches for the g++ compiler that
  344. will permit people using g++ on SVr4 systems to build ELF format shared
  345. libraries.  Contact <rfg@netcom.com> for further information.
  346.  
  347.    The GNU linker has not been ported to as many platforms as g++ has,
  348. so you may be forced to use collect.
  349.  
  350.    If you use collect, you don't need to get something extra and figure
  351. out how to install it; the standard gcc installation procedure will do
  352. it for you.
  353.  
  354.    In conclusion, I don't see a clear win for either alternative at this
  355. point.  Take your pick.
  356.  
  357.  
  358. Should I use the GNU assembler, or my vendor's assembler?
  359. =========================================================
  360.  
  361.    This depends on your platform and your decision about the GNU
  362. linker.  For most platforms, you'll need to use gas if you use the GNU
  363. linker.  For some platforms, you have no choice; check the gcc
  364. installation notes to see whether you must use gas.  But you can
  365. usually use the vendor's assembler if you don't use the GNU linker.
  366.  
  367.    The GNU assembler assembles faster than many native assemblers;
  368. however, on many platforms it cannot support the local debugging format.
  369.  
  370.  
  371. Should I use the GNU C library?
  372. ===============================
  373.  
  374.    At this point in time, no.  The GNU C library is still very young,
  375. and libg++ still conflicts with it in some places.  Use your native C
  376. library unless you know a lot about the gory details of libg++ and
  377. gnu-libc.  This will probably change in the future.
  378.  
  379.  
  380. Strange assembler errors when linking C++ programs
  381. ==================================================
  382.  
  383.    "I've installed gcc and it seemed to go OK, but when I attempt to
  384. link any C++ program, I'm getting strange errors from the assembler!
  385. How can that be?"
  386.  
  387.    The messages in question might look something like
  388.  
  389.      as: "/usr/tmp/cca14605.s", line 8: error: statement syntax
  390.      as: "/usr/tmp/cca14605.s", line 14: error: statement syntax
  391.  
  392.    (on a Sun, different on other platforms).  The important thing is
  393. that the errors come out at the link step, *not* when a C++ file is
  394. being compiled.
  395.  
  396.    Here's what's going on: the collect2 program uses the Unix "nm"
  397. program to obtain a list of symbols for the global constructors and
  398. destructors, and it builds a little assembly language module that will
  399. permit them all to be called.  If you're seeing this symptom, you have
  400. an old version of GNU nm somewhere on your path.  This old version
  401. prints out symbol names in a format that the collect2 program does not
  402. expect, so bad assembly code is generated.
  403.  
  404.    The solution is either to remove the old version of GNU nm from your
  405. path (and that of everyone else who uses g++), or to install a newer
  406. version (it is part of the GNU "binutils" package).  Recent versions of
  407. GNU nm do not have this problem.
  408.  
  409.  
  410. Problems building libg++ on 386/486
  411. ===================================
  412.  
  413.    Attempts to install libg++ on 386 or 486 systems running ports of
  414. SVR4 have problems because of bugs in debugging support on that
  415. platform.  Briefly, debugging does not currently work right yet for
  416. C++.  You should be able to build the library successfully by deleting
  417. the `-g' flag from the Makefiles (this should no longer be necessary
  418. with gcc 2.4.x although debugging still doesn't work).
  419.  
  420.    See the section entitled "Debugging on SVR4 systems."
  421.  
  422.  
  423. Other problems building libg++
  424. ==============================
  425.  
  426.    "I am having trouble building libg++.  Help!"
  427.  
  428.    On some platforms (for example, Ultrix), you may see errors
  429. complaining about being unable to open dummy.o.  On other platforms
  430. (for example, SunOS), you may see problems having to do with the type
  431. of size_t.  The fix for these problems is to make libg++ by saying
  432. "make CC=gcc".  According to Per Bothner, it should no longer be
  433. necessary to specify "CC=gcc" for libg++-2.3.1 or later.
  434.  
  435.    "I built and installed libg++, but g++ can't find it.  Help!"
  436.  
  437.    The string given to `configure' that identifies your system must be
  438. the same when you install libg++ as it was when you installed gcc.
  439. Also, if you used the `--prefix' option to install gcc somewhere other
  440. than `/usr/local', you must use the same value for `--prefix' when
  441. installing libg++, or else g++ will not be able to find g++.
  442.  
  443.  
  444. But I'm *still* having problems with `size_t'!
  445. ==============================================
  446.  
  447.    "I did all that, and I'm *still* having problems with disagreeing
  448. definitions of size_t, SIZE_TYPE, and the type of functions like
  449. `strlen'."
  450.  
  451.    The problem may be that you have an old version of `_G_config.h'
  452. lying around.  As of libg++ version 2.4, `_G_config.h', since it is
  453. platform-specific, is inserted into a different directory; most include
  454. files are in `$prefix/lib/g++-include', but this file now lives in
  455. `$prefix/$arch/include'.  If, after upgrading your libg++, you find that
  456. there is an old copy of `_G_config.h' left around, remove it, otherwise
  457. g++ will find the old one first.
  458.  
  459.  
  460. Do I need to rebuild libg++ to go with my new g++?
  461. ==================================================
  462.  
  463.    "After I upgraded g++ to the latest version, I'm seeing undefined
  464. symbols."
  465.  
  466.    or
  467.  
  468.    "If I upgrade to a new version of g++, do I need to reinstall
  469. libg++?"
  470.  
  471.    This depends; as a rule, some upgrades will require rebuilding libg++
  472. and others will not.  Both versions 2.3.3 and 2.4.0 introduced some
  473. incompatibilities with previous versions.  For 2.3.3, the name mangling
  474. of certain virtual table names changed, which introduced an
  475. incompatiblity.  For 2.4.0, the type of "size_t" changed on Suns from
  476. int (as declared by the include files provided by Sun) to unsigned long
  477. (the ANSI C and draft ANSI C++ standards declare that size_t must be
  478. unsigned, and the GCC maintainers are now correcting this "bug").
  479.  
  480.    With version 2.5 of g++ and libg++, major changes were made in the
  481. way that prototypes are provided for system functions.  Before, libg++
  482. provided prototypes for such functions in the g++-include directory.
  483. As of 2.5, gcc creates fixed headers suitable for both C and C++ as part
  484. of its installation process.  You definitely need to install a new
  485. libg++ to go with a 2.5.x release of g++.
  486.  
  487.    As a rule, the first two digits of your g++ and libg++ should be the
  488. same.
  489.  
  490.  
  491. User Problems
  492. *************
  493.  
  494.  
  495. gcc 2.5.x broke my code!  Changes in function overloading
  496. =========================================================
  497.  
  498.    "I have a program that worked just fine with older g++ versions, but
  499. as of version 2.5.x it doesn't work anymore.  Help!"
  500.  
  501.    While it's always possible that a new bug has been introduced into
  502. the compiler, it's also possible that you have been relying on bugs in
  503. older versions of g++.  For example, version 2.5.0 was the first
  504. version of g++ to correctly implement the "hiding rule."  That is, if
  505. you have an overloaded function in a base class, and in a derived class
  506. you redefine one of the names, the other names are effectively "hidden".
  507. *All* the names from the baseclass need to be redefined in the derived
  508. class.  See section 13.1 of the ARM: "A function member of a derived
  509. class is *not* in the same scope as a function member of the same name
  510. in a base class".
  511.  
  512.    Here's an example that is handled incorrectly by g++ versions before
  513. 2.5.0 and correctly by newer versions:
  514.  
  515.      class Base {
  516.      public:
  517.          void foo(int);
  518.      };
  519.      
  520.      class Derived : public Base {
  521.      public:
  522.          void foo(double);  // *note that Base::foo(int) is hidden*
  523.      };
  524.      
  525.      main() {
  526.          Derived d;
  527.          d.foo(2); // *Derived::foo(double), not Base::foo(int), is called*
  528.      }
  529.  
  530.  
  531. Where can I find a demangler?
  532. =============================
  533.  
  534.    A g++-compatible demangler named `c++filt' can be found in the
  535. `binutils' distribution.  This distribution (which also contains the
  536. GNU linker) can be found at any GNU archive site.
  537.  
  538.  
  539. Where can I find a version of etags for C++?
  540. ============================================
  541.  
  542.    The libg++ distribution contains a version of etags that works for
  543. C++ code.  Look in `libg++/utils'.  It's not built by default when you
  544. install libg++, but you can cd to that directory and type
  545.  
  546.      make etags
  547.  
  548.    after you've installed libg++.
  549.  
  550.  
  551. Linker reports undefined symbols for static data members
  552. ========================================================
  553.  
  554.    "g++ reports undefined symbols for all my static data members when I
  555. link, even though the program works correctly for compiler XYZ.  What's
  556. going on?"
  557.  
  558.    The problem is almost certainly that you don't give definitions for
  559. your static data members.  If you have
  560.  
  561.      class Foo {
  562.          ...
  563.          void method();
  564.          static int bar;
  565.      };
  566.  
  567.    you have only declared that there is an int named Foo::bar and a
  568. member function named Foo::method that is defined somewhere.  You still
  569. need to defined BOTH method() and bar in some source file.  According
  570. to the draft ANSI standard, you must supply an initializer, such as
  571.  
  572.      int Foo::bar = 0;
  573.  
  574. in one (and only one) source file.
  575.  
  576.  
  577. g++ won't accept the placement new syntax.
  578. ==========================================
  579.  
  580.    "I have a program that uses the "placement syntax" of operator new,
  581. e.g.
  582.  
  583.         new (somewhere) T;
  584.  
  585. and g++ won't accept it."
  586.  
  587.    Up until version 2.3.1, g++ accepted an alternate form of the
  588. placement syntax, for historical reasons; use
  589.  
  590.         new {somewhere} T;
  591.  
  592. if you are using g++-2.2.2 or older.
  593.  
  594.    As of 2.3.1, g++ finally fixed this, using the standard ARM syntax
  595. for "placement new".  A few remaining glitches were fixed in 2.3.2.  The
  596. only remaining problem is with declarators for pointers to functions;
  597.  
  598.      new (void (*)(int));  // confuses gcc 2.3.2
  599.      new (a) (void (*)(int)); // ditto
  600.  
  601.    These can be worked around with a typedef:
  602.  
  603.      typedef void (*fun)(int);
  604.      new fun;
  605.      new (a) fun;
  606.  
  607.  
  608. Overloaded increment (`++') and decrement (`--') operators
  609. ==========================================================
  610.  
  611.    "g++ doesn't seem to distinguish the prefix and postfix forms of
  612. `operator++'.  What gives?"
  613.  
  614.    This is a relatively new feature in the C++ language.  The solution
  615. is to upgrade your compiler; distinguishing the prefix and postfix cases
  616. of `operator++' and `operator--' was first implemented in g++ version
  617. 2.4.1.
  618.  
  619.    For backward compatibility, if a class declares a prefix version of
  620. `operator++' (or `operator--') but no postfix version, and code
  621. attempts to use `++' (or `--') as a postfix operator, g++ will use the
  622. prefix version (unless the `-pedantic' flag is set).  This feature is
  623. to avoid breaking old code.
  624.  
  625.  
  626. I think I have found a bug in g++.
  627. ==================================
  628.  
  629.    "I think I have found a bug in g++, but I'm not sure.  How do I know,
  630. and who should I tell?"
  631.  
  632.    First, see the excellent section on bugs and bug reports in the gcc
  633. manual (which is included in the gcc distribution).  As a short summary
  634. of that section: if the compiler gets a fatal signal, for any input,
  635. it's a bug (newer versions of g++ will ask you to send in a bug report
  636. when they detect an error in themselves).  Same thing for producing
  637. invalid assembly code.
  638.  
  639.    When you report a bug, make sure to describe your platform (the type
  640. of computer, and the version of the operating system it is running) and
  641. the version of the compiler that you are running.  Also provide enough
  642. code so that the g++ maintainers can duplicate your bug.
  643.  
  644.    I will add some extra notes that are C++-specific, since the notes
  645. from the gcc documentation are generally C-specific.
  646.  
  647.    First, mail your bug report to "bug-g++@prep.ai.mit.edu".  You may
  648. also post to gnu.g++.bug, but it's better to use mail, particularly if
  649. you have any doubt as to whether your news software generates correct
  650. reply addresses.  Don't mail C++ bugs to bug-gcc@prep.ai.mit.edu.
  651.  
  652.    If your bug involves libg++ rather than the compiler, mail to
  653. bug-lib-g++@prep.ai.mit.edu.  If you're not sure, choose one, and if you
  654. guessed wrong, the maintainers will forward it to the other list.
  655.  
  656.    Second, if your program does one thing, and you think it should do
  657. something else, it is best to consult a good reference if in doubt.  The
  658. standard reference is "The Annotated C++ Reference Manual", by Ellis and
  659. Stroustrup (copyright 1990, ISBN #0-201-51459-1).  This is what they're
  660. talking about on the net when they refer to "the ARM".
  661.  
  662.    The reference manual, without annotations, also appears in
  663. Stroustrup's "The C++ Programming Language, Second Edition" (copyright
  664. 1991, ISBN #0-201-53992-6).  Both books are published by Addison-Wesley.
  665.  
  666.    Note that the behavior of (any version of) AT&T's "cfront" compiler
  667. is NOT the standard for the language.
  668.  
  669.  
  670. Porting programs from other compilers to g++
  671. ============================================
  672.  
  673.    "I have a program that runs on <some other C++ compiler>, and I want
  674. to get it running under g++.  Is there anything I should watch out for?"
  675.  
  676.    First, see the questions on placement new syntax and static data
  677. members.
  678.  
  679.    Secondly, if the porting problem relates to the resolution of
  680. overloaded operators or functions, you might try the
  681. `-fansi-overloading' switch in g++ 2.5.0 or later.  This switch enables
  682. new code that attempts to match the ARM specification of overloaded
  683. argument resolution better.
  684.  
  685.    There are two other reasons why a program that worked under one
  686. compiler might fail under another: your program may depend on the order
  687. of evaluation of side effects in an expression, or it may depend on the
  688. lifetime of a temporary (you may be assuming that a temporary object
  689. "lives" longer than the standard guarantees).  As an example of the
  690. first:
  691.  
  692.      void func(int,int);
  693.      
  694.      int i = 3;
  695.      func(i++,i++);
  696.  
  697.    Novice programmers think that the increments will be evaluated in
  698. strict left-to-right order.  Neither C nor C++ guarantees this; the
  699. second increment might happen first, for example.  func might get 3,4,
  700. or it might get 4,3.
  701.  
  702.    The second problem often happens with classes like the libg++ String
  703. class.  Let's say I have
  704.  
  705.      String func1();
  706.      void func2(const char*);
  707.  
  708.    and I say
  709.  
  710.      func2(func1());
  711.  
  712.    because I know that class String has an "operator const char*".  So
  713. what really happens is
  714.  
  715.      func2(func1().convert());
  716.  
  717.    where I'm pretending I have a convert() method that is the same as
  718. the cast.  This is unsafe, because the temporary String object may be
  719. deleted after its last use (the call to the conversion function),
  720. leaving the pointer pointing to garbage, so by the time func2 is
  721. called, it gets an invalid argument.
  722.  
  723.    Both the cfront and the g++ behaviors are legal according to the ARM,
  724. but the powers that be have decided that compiler writers were given
  725. too much freedom here.  The ANSI C++ committee has now come to a
  726. resolution of the lifetime of temporaries problem: they specify that
  727. temporaries should be deleted at end-of-statement (and at a couple of
  728. other points).  This means that g++ now deletes temporaries too early,
  729. and cfront deletes temporaries too late.
  730.  
  731.    For now, the safe way to write such code is to give the temporary a
  732. name, which forces it to live until the end of the scope of the name.
  733. For example:
  734.  
  735.      String& tmp = func1();
  736.      func2(tmp);
  737.  
  738.    Finally, like all compilers (but especially C++ compilers, it seems),
  739. g++ has bugs, and you may have tweaked one.  If so, please file a bug
  740. report (after checking the above issues).
  741.  
  742.  
  743. Why does g++ mangle names differently from other C++ compilers?
  744. ===============================================================
  745.  
  746.    See the answer to the next question.
  747.  
  748.  
  749. Why can't g++ code link with code from other C++ compilers?
  750. ===========================================================
  751.  
  752.    "Why can't I link g++-compiled programs against libraries compiled by
  753. some other C++ compiler?"
  754.  
  755.    Some people think that, if only the FSF and Cygnus Support folks
  756. would stop being stubborn and mangle names the same way that, say,
  757. cfront does, then any g++-compiled program would link successfully
  758. against any cfront-compiled library and vice versa.  Name mangling is
  759. the least of the problems.  Compilers differ as to how objects are laid
  760. out, how multiple inheritance is implemented, how virtual function
  761. calls are handled, and so on, so if the name mangling were made the
  762. same, your programs would link against libraries provided from other
  763. compilers but then crash when run.  For this reason, the ARM
  764. *encourages* compiler writers to make their name mangling different
  765. from that of other compilers for the same platform.  Incompatible
  766. libraries are then detected at link time, rather than at run time.
  767.  
  768.  
  769. What documentation exists for g++ 2.x?
  770. ======================================
  771.  
  772.    Relatively little.  While the gcc manual that comes with the
  773. distribution has some coverage of the C++ part of the compiler, it
  774. focuses mainly on the C compiler (though the information on the "back
  775. end" pertains to C++ as well).  Still, there is useful information on
  776. the command line options and the #pragma interface and #pragma
  777. implementation directives in the manual.  There is a Unix-style manual
  778. entry, "g++.1", in the gcc-2.x distribution; the information here is a
  779. subset of what is in the manual.
  780.  
  781.    You can buy a nicely printed and bound copy of this manual from the
  782. FSF; see above for ordering information.
  783.  
  784.    A draft of a document describing the g++ internals appears in the gcc
  785. distribution (called g++int.texi); it is still incomplete.
  786.  
  787.  
  788. What are the differences between g++ and the ARM specification of C++?
  789. ======================================================================
  790.  
  791.    The chief thing missing from g++ that is in the ARM is exceptions.
  792. There are bits and pieces of exception code present, but it is not
  793. presently usable.
  794.  
  795.    The template implementation is still new.  The implementation in
  796. 2.5.x represents a considerable improvement over that of previous
  797. releases, but it has a long way to go.  This continues to improve from
  798. release to release.
  799.  
  800.    g++ does not implement a separate pass to instantiate template
  801. functions and classes at this point; for this reason, it will not work,
  802. for the most part, to declare your template functions in one file and
  803. define them in another.  The compiler will need to see the entire
  804. definition of the function, and will generate a static copy of the
  805. function in each file in which it is used.  For 2.5.0, however, a new
  806. switch `-fexternal-templates' was added; this makes it possible to have
  807. only one globally visible copy of a given template expansion in your
  808. executable.  See the gcc manual for details.
  809.  
  810.    Some features that the ANSI/ISO standardization committee has voted
  811. in that don't appear in the ARM are supported, notably the `mutable'
  812. keyword, in version 2.5.x.
  813.  
  814.    As with any beta-test compiler, there are bugs.  You can help improve
  815. the compiler by submitting detailed bug reports.
  816.  
  817.    One of the weakest areas of g++ other than templates is the
  818. resolution of overloaded functions and operators in complex cases.  The
  819. usual symptom is that in a case where the ARM says that it is ambiguous
  820. which function should be chosen, g++ chooses one (often the first one
  821. declared).  This is usually not a problem when porting C++ code from
  822. other compilers to g++, but shows up as errors when code developed under
  823. g++ is ported to other compilers.
  824.  
  825.    As of 2.5.0, the overloading code has been rewritten.  For now, you
  826. must specify the option `-fansi-overloading' to get the new code, since
  827. there were some important users actually depending on g++'s incorrect
  828. resolution of ambiguities.  This switch should disappear in the future.
  829. If a program that compiled under previous g++ versions now reports that
  830. a use of an overloaded function is ambiguous, it is likely that the old
  831. g++ was letting you write buggy code and the new one is detecting the
  832. problem.  If in doubt, consult the ARM.
  833.  
  834.    [A full bug list would be very long indeed, so I won't put one here.
  835. I may add a list of frequently-reported bugs and "non-bugs" like the
  836. static class members issue mentioned above].
  837.  
  838.  
  839. Will g++ compile InterViews?  The NIH class library?
  840. ====================================================
  841.  
  842.    The NIH class library uses a non-portable, compiler-dependent hack
  843. to initialize itself, which makes life difficult for g++ users.  It
  844. will not work without modification, and I don't know what modifications
  845. are required or whether anyone has done them successfully.
  846.  
  847.    In short, it's not going to happen any time soon (previous FAQs
  848. referred to patches that a new NIHCL release would hopefully contain,
  849. but this hasn't happened).
  850.  
  851.    [ From Steinar Bang <steinarb@idt.unit.no>]
  852.  
  853.    InterViews 3.1 compiles and runs with gcc-2.3.3 and libg++-2.3,
  854. except that the "doc" application immediately dumps core when you try
  855. to run it.  There is also a small glitch with idraw.
  856.  
  857.    There is a patch for InterViews 3.1 from Johan Garpendahl
  858. <garp@isy.liu.se> available for FTP from site "ugle.unit.no".  It is in
  859. the file
  860.  
  861.    `/pub/X11/contrib/InterViews/g++/3.1-beta3-patch'.
  862.  
  863.    This fixes two things: the Doc coredump, and the pattern menu of
  864. idraw.  Read the instructions at the start of the file.
  865.  
  866.    I think that as of version 2.5.6, the standard g++ will compile the
  867. standard 3.1 InterViews completely successfully.  I'd appreciate a
  868. confirmation.
  869.  
  870.  
  871. Debugging on SVR4 systems
  872. =========================
  873.  
  874.    "When I use the `-g' flag on C++ code on a System V Release 4 system,
  875. I get lots of undefined symbols at link time.  Why?  Help!"
  876.  
  877.    Most systems based on System V Release 4 (except Solaris) encode
  878. symbolic debugging information in a format known as `DWARF'.
  879.  
  880.    Although the GNU C compiler already knows how to write out symbolic
  881. debugging information in the DWARF format, the GNU C++ compiler does
  882. not yet have this feature, nor is it likely to in the immediate future.
  883.  
  884.    Ron Guilmette has done a great deal of work to try to get the GNU
  885. C++ com- piler to produce DWARF format symbolic debugging information
  886. (for C++ code) but he gave up on the project because of a lack of
  887. funding and/or interest from the g++ user community.  If you have a
  888. strong desire to see this project completed, contact Ron at
  889. <rfg@netcom.com>.
  890.  
  891.  
  892. What are the rules for shipping code built with g++ and libg++?
  893. ***************************************************************
  894.  
  895.    "Is it is possible to distribute programs for profit that are created
  896. with g++ and use the g++ libraries?"
  897.  
  898.    I am not a lawyer, and this is not legal advice.  In any case, I have
  899. little interest in telling people how to violate the spirit of the GNU
  900. licenses without violating the letter.  This section tells you how to
  901. comply with the intention of the GNU licenses as best I understand them.
  902.  
  903.    The FSF has no objection to your making money.  Its only interest is
  904. that source code to their programs, and libraries, and to modified
  905. versions of their programs and libraries, is always available.
  906.  
  907.    The short answer is that you do not need to release the source to
  908. your program, but you can't just ship a stripped executable either.
  909.  
  910.    Compiling your code with a GNU compiler does not affect its
  911. copyright; it is still yours.  However, in order to ship code that
  912. links in a GNU library such as libg++ there are certain rules you must
  913. follow.  The rules are described in the file COPYING.LIB that
  914. accompanies gcc distributions; it is also included in the libg++
  915. distribution.  See that file for the exact rules.  The agreement is
  916. called the Library GNU Public License or LGPL.  It is much "looser"
  917. than the GNU Public License, or GPL, that covers must GNU programs.
  918.  
  919.    Here's the deal: let's say that you use some version of libg++,
  920. completely unchanged, in your software, and you want to ship only a
  921. binary form of your code.  You can do this, but there are several
  922. special requirements.  If you want to use libg++ but ship only object
  923. code for your code, you have to ship source for libg++ (or ensure
  924. somehow that your customer already has the source for the exact version
  925. you are using), and ship your application in linkable form.  You cannot
  926. forbid your customer from reverse-engineering or extending your program
  927. by exploiting its linkable form.
  928.  
  929.    Furthermore, if you modify libg++ itself, you must provide source
  930. for your modifications (making a derived class does not count as
  931. modifying the library - that is "a work that uses the library").
  932.  
  933.  
  934. Concept Index
  935. *************
  936.  
  937. -- 
  938. -- Joe Buck    jbuck@synopsys.com
  939. Posting from but not speaking for Synopsys, Inc.
  940. Formerly jbuck@<various-hosts>.eecs.berkeley.edu
  941.